package com.qifan.energy.http.net;

import com.qifan.energy.bean.vo.AddressAddVO;
import com.qifan.energy.bean.vo.BalanceWithdrawalVO;
import com.qifan.energy.bean.vo.CartItemVO;
import com.qifan.energy.bean.vo.GenerateOrderParamVO;
import com.qifan.energy.bean.vo.LoginVO;
import com.qifan.energy.bean.vo.RegisterVO;
import com.qifan.energy.bean.vo.UpdateInfoVO;
import com.qifan.energy.bean.vo.UpdatePwdVO;
import com.qifan.energy.http.response.MyObserver;
import com.qifan.energy.bean.request.MemberDistributeParam;

import java.util.List;
import java.util.WeakHashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/* 静态工具类 */
public class NetUtils {

    /* 保存token */
    public static void saveToken(String token){
        RetrofitFactory.getInstance().setToken(token);
    }

    /* 删除token */
    public static void removeToken(){
        RetrofitFactory.getInstance().setToken("");
    }

    /* 获取验证码 */
    public static void getAuthCode(String telephone, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().getAuthCode(telephone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 用户注册 */
    public static void regist(RegisterVO registerVO, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().regist(registerVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 用户登录 */
    public static void login(LoginVO loginVO, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().login(loginVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
        removeToken();
    }

    /* 用户信息 */
    /*public static void userInfo(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().userInfo()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }*/

    /* 刷新token */
    public static void refreshToken(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().refreshToken()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 退出登录 */
    public static void logout(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().logout()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 申请成为合伙人 */
    public static void ssoApplyPartner(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().ssoApplyPartner()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 修改密码(重置密码|登录) */
    public static void updatePwd(UpdatePwdVO updatePwdVO, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().updatePwd(updatePwdVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 修改用户信息 */
    public static void updateInfo(UpdateInfoVO updateInfoVO, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().updateInfo(updateInfoVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 首页列表数据 */
    public static void homeContent(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().homeContent()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 获取首页商品分类 */
    /*public static void homeProductCateList(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().homeProductCateList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }*/

    /* 分页获取推荐商品 */
    /*public static void homeRecommendProductList(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().homeRecommendProductList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }*/

    /* 分销商品区商品列表 */
    public static void homeDistributeProductList(Integer pageNum, Integer pageSize, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().homeDistributeProductList(pageNum,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 普通商品区商品列表 */
    public static void homeNormalProductList(Integer pageNum, Integer pageSize, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().homeNormalProductList(pageNum,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 购物车列表 */
    public static void cartList(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().cartList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 购物车列表 */
    public static void cartAdd(CartItemVO cartItemVO, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().cartAdd(cartItemVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 清空购物车接口 */
    public static void cartClear(MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().cartClear()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 批量删除购物车接口 */
    public static void cartDelete(List<Integer> ids, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().cartDelete(ids)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 修改购物车中商品的规格接口 */
    public static void cartUpdateAttr(CartItemVO cartItemVO, MyObserver observer) {
        RetrofitFactory.getInstance().getHttpService().cartUpdateAttr(cartItemVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 根据列表Id查询商品详情 */
    public static void productDetail(String id,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().productDetail(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 修改购物车中某个商品的数量 */
    public static void cartUpdateQuantity(Integer id,Integer quantity,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().cartUpdateQuantity(id,quantity)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 修改购物车中某个商品的数量 */
    public static void productSearch(String keyword, Integer pageNum, Integer pageSize,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().productSearch(keyword, pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 显示所有收货地址 */
    public static void memberAddressList(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberAddressList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 显示所有收货地址 */
    public static void memberAddressDefaultAddress(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberAddressDefaultAddress()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 添加收货地址 */
    public static void memberAddressAdd(AddressAddVO addressAddVO, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberAddressAdd(addressAddVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 删除收货地址 */
    public static void memberAddressDelete(Integer id,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberAddressDelete(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 修改收货地址 */
    public static void memberAddressUpdate(Integer id,AddressAddVO addressAddVO,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberAddressUpdate(id,addressAddVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 修改收货地址(默认地址) */
    public static void memberAddressUpdateDefaultAddress(Integer id, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberAddressUpdateDefaultAddress(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* oss上传签名生成 */
    public static void aliyunOssPolicy(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().aliyunOssPolicy()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* oss上传成功回调 */
    public static void aliyunOssCallback(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().aliyunOssCallback()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 根据购物车信息生成确认单信息 */
    public static void orderGenerateConfirmOrder(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderGenerateConfirmOrder()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 立即购买 */
    public static void orderBuyNow(CartItemVO cartItemVO, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderBuyNow(cartItemVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 根据购物车信息下单 */
    public static void orderGenerateOrder(GenerateOrderParamVO orderParamVO, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderGenerateOrder(orderParamVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 根据订单支付(支付宝) */
    public static void orderAlipay(GenerateOrderParamVO orderParamVO ,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderAlipay(orderParamVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 根据订单支付(微信) */
    public static void orderWXPay(GenerateOrderParamVO orderParamVO ,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderWXPay(orderParamVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 支付成功的回调 */
    public static void orderPaySuccess(GenerateOrderParamVO orderParamVO, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderPaySuccess(orderParamVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 用户取消订单 */
    public static void orderCancelUserOrder(Integer orderId,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderCancelUserOrder(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 用户确认收货 */
    public static void orderConfirmReceiveOrder(Integer orderId,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderConfirmReceiveOrder(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }


    /* 用户删除订单 */
    public static void orderDeleteOrder(Integer orderId,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderDeleteOrder(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 按状态分页获取用户订单列表
    * status: 订单状态：-1->全部；0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭
    *  */
    public static void orderList(Integer status,Integer pageNum,Integer pageSize,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().orderList(status,pageNum,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 获取用户优惠券列表 	优惠券筛选类型:0->未使用；1->已使用；2->已过期 */
    public static void memberCouponList(Integer useStatus, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberCouponList(useStatus)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 绑定支付宝 */
    public static void memberBalanceAliPay(String aliPayAccount, String realName, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberBalanceAliPay(aliPayAccount,realName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 用户信息结果获取接口 */
    public static void memberCenterContent(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberCenterContent()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 申请提现 */
    public static void memberBalanceWithdrawalAdd(BalanceWithdrawalVO balanceWithdrawalVO, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberBalanceWithdrawalAdd(balanceWithdrawalVO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 获取余额信息 */
    public static void memberBalanceBalanceResult(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberBalanceBalanceResult()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 查看余额变动记录 change_type '改变类型：0->增加；1->减少' change_reason '改变原因：0->分销获得；1->提现消耗；2->房间收益；3->合伙人收益' */
    public static void memberBalanceHistorySearch(Integer changeType,Integer changeReason,Integer pageNum,Integer pageSize,MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberBalanceHistorySearch(changeType,changeReason,pageNum,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 获取游戏分信息 */
    public static void memberGameIntegrationGameIntegrationResult(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberGameIntegrationGameIntegrationResult()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 获取时间卡信息 */
    public static void memberTimeCardTimeCardResult(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberTimeCardTimeCardResult()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 使用游戏分兑换 */
    public static void memberDistributeExchange(MemberDistributeParam memberDistributeParam, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberDistributeExchange(memberDistributeParam)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 查询分销 */
    public static void memberDistributeSearch(Integer saleStatus,Integer pageNum, Integer pageSize, MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberDistributeSearch(saleStatus,pageNum,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 我的人脉 */
    public static void memberCenterContacts(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().memberCenterContacts()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /* 版本控制 */
    public static void appVersionControl(MyObserver observer){
        RetrofitFactory.getInstance().getHttpService().appVersionControl()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
